import {defineConfig, ConfigEnv, UserConfig} from 'vite'
import react from '@vitejs/plugin-react'
import {resolve} from "path";
import { createHtmlPlugin } from "vite-plugin-html";
export default defineConfig((mode: ConfigEnv): UserConfig => {

    return {
        base: "./",
        // alias config
        resolve: {
            alias: {
                "@": resolve(__dirname, "./src")
            }
        },
        // global css
        css: {
            preprocessorOptions: {
                less: {
                    modifyVars: {
                        "primary-color": "rgb(0, 82, 204)",
                        "font-size-base": "16px",
                    },
                    javascriptEnabled: true,
                    additionalData: `@import "@/styles/var.less";`
                }
            }
        },
        // server config
        server: {
            host: "0.0.0.0", // 服务器主机名，如果允许外部访问，可设置为"0.0.0.0"
            port: 8888,
            // open: number,
            cors: true,
            // https: false,
            // 代理跨域（mock 不需要配置，这里只是个事列）
            proxy: {
                "/api": {
                    target: "https://mock.mengxuegu.com/mock/62abda3212c1416424630a45", // easymock
                    changeOrigin: true,
                    rewrite: path => path.replace(/^\/api/, "")
                }
            }
        },
        // plugins
        plugins: [
            react(),
            createHtmlPlugin({
                inject: {
                    data: {
                        title: "笔记"
                    }
                }
            }),
            // * EsLint 报错信息显示在浏览器界面上
            // eslintPlugin(),
        ],
        // build configure
        build: {
            outDir: "dist",
            // esbuild 打包更快，但是不能去除 console.log，去除 console 使用 terser 模式
            minify: "esbuild",
            // minify: "terser",
            // terserOptions: {
            // 	compress: {
            // 		drop_console: viteEnv.VITE_DROP_CONSOLE,
            // 		drop_debugger: true
            // 	}
            // },
            rollupOptions: {
                output: {
                    // Static resource classification and packaging
                    chunkFileNames: "assets/js/[name]-[hash].js",
                    entryFileNames: "assets/js/[name]-[hash].js",
                    assetFileNames: "assets/[ext]/[name]-[hash].[ext]"
                }
            }
        }
    }
})
